/*eslint-disable*/
/*.................MD5.........................*/
;(function() {
  var hexcase = 0
  var b64pad = ''
  var chrsz = 8
  function hex_md5(s) {
    return binl2hex(core_md5(str2binl(s), s.length * chrsz))
  }
  function b64_md5(s) {
    return binl2b64(core_md5(str2binl(s), s.length * chrsz))
  }
  function str_md5(s) {
    return binl2str(core_md5(str2binl(s), s.length * chrsz))
  }
  function hex_hmac_md5(key, data) {
    return binl2hex(core_hmac_md5(key, data))
  }
  function b64_hmac_md5(key, data) {
    return binl2b64(core_hmac_md5(key, data))
  }
  function str_hmac_md5(key, data) {
    return binl2str(core_hmac_md5(key, data))
  }
  function md5_vm_test() {
    return hex_md5('abc') == '900150983cd24fb0d6963f7d28e17f72'
  }
  function core_md5(x, len) {
    x[len >> 5] |= 128 << len % 32
    x[(((len + 64) >>> 9) << 4) + 14] = len
    var a = 1732584193
    var b = -271733879
    var c = -1732584194
    var d = 271733878
    for (var i = 0; i < x.length; i += 16) {
      var olda = a
      var oldb = b
      var oldc = c
      var oldd = d
      a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936)
      d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586)
      c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819)
      b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330)
      a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897)
      d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426)
      c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341)
      b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983)
      a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416)
      d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417)
      c = md5_ff(c, d, a, b, x[i + 10], 17, -42063)
      b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162)
      a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682)
      d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101)
      c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290)
      b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329)
      a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510)
      d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632)
      c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713)
      b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302)
      a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691)
      d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083)
      c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335)
      b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848)
      a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438)
      d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690)
      c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961)
      b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501)
      a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467)
      d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784)
      c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473)
      b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734)
      a = md5_hh(a, b, c, d, x[i + 5], 4, -378558)
      d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463)
      c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562)
      b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556)
      a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060)
      d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353)
      c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632)
      b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640)
      a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174)
      d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222)
      c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979)
      b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189)
      a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487)
      d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835)
      c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520)
      b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651)
      a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844)
      d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415)
      c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905)
      b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055)
      a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571)
      d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606)
      c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523)
      b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799)
      a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359)
      d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744)
      c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380)
      b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649)
      a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070)
      d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379)
      c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259)
      b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551)
      a = safe_add(a, olda)
      b = safe_add(b, oldb)
      c = safe_add(c, oldc)
      d = safe_add(d, oldd)
    }
    return Array(a, b, c, d)
  }
  function md5_cmn(q, a, b, x, s, t) {
    return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b)
  }
  function md5_ff(a, b, c, d, x, s, t) {
    return md5_cmn((b & c) | (~b & d), a, b, x, s, t)
  }
  function md5_gg(a, b, c, d, x, s, t) {
    return md5_cmn((b & d) | (c & ~d), a, b, x, s, t)
  }
  function md5_hh(a, b, c, d, x, s, t) {
    return md5_cmn(b ^ c ^ d, a, b, x, s, t)
  }
  function md5_ii(a, b, c, d, x, s, t) {
    return md5_cmn(c ^ (b | ~d), a, b, x, s, t)
  }
  function core_hmac_md5(key, data) {
    var bkey = str2binl(key)
    if (bkey.length > 16) {
      bkey = core_md5(bkey, key.length * chrsz)
    }
    var ipad = Array(16),
      opad = Array(16)
    for (var i = 0; i < 16; i++) {
      ipad[i] = bkey[i] ^ 909522486
      opad[i] = bkey[i] ^ 1549556828
    }
    var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz)
    return core_md5(opad.concat(hash), 512 + 128)
  }
  function safe_add(x, y) {
    var lsw = (x & 65535) + (y & 65535)
    var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
    return (msw << 16) | (lsw & 65535)
  }
  function bit_rol(num, cnt) {
    return (num << cnt) | (num >>> (32 - cnt))
  }
  function str2binl(str) {
    var bin = Array()
    var mask = (1 << chrsz) - 1
    for (var i = 0; i < str.length * chrsz; i += chrsz) {
      bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << i % 32
    }
    return bin
  }
  function binl2str(bin) {
    var str = ''
    var mask = (1 << chrsz) - 1
    for (var i = 0; i < bin.length * 32; i += chrsz) {
      str += String.fromCharCode((bin[i >> 5] >>> i % 32) & mask)
    }
    return str
  }
  function binl2hex(binarray) {
    var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef'
    var str = ''
    for (var i = 0; i < binarray.length * 4; i++) {
      str +=
        hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 15) +
        hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 15)
    }
    return str
  }
  function binl2b64(binarray) {
    var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    var str = ''
    for (var i = 0; i < binarray.length * 4; i += 3) {
      var triplet =
        (((binarray[i >> 2] >> (8 * (i % 4))) & 255) << 16) |
        (((binarray[(i + 1) >> 2] >> (8 * ((i + 1) % 4))) & 255) << 8) |
        ((binarray[(i + 2) >> 2] >> (8 * ((i + 2) % 4))) & 255)
      for (var j = 0; j < 4; j++) {
        if (i * 8 + j * 6 > binarray.length * 32) {
          str += b64pad
        } else {
          str += tab.charAt((triplet >> (6 * (3 - j))) & 63)
        }
      }
    }
    return str
  }
  window.hex_md5 = hex_md5
  window.b64_md5 = b64_md5
  window.str_md5 = str_md5
})()
;(function() {
  // 创建全局定时器
  var controlTimer = null
  var bus = new Vue()
  var condition = {
    speedTxt: '正常',
    speedList: {
      '0.8X': 0.8,
      正常: 1,
      '1.25X': 1.25,
      '1.5X': 1.5,
      '2X': 2
    },
    isNewIE: function() {
      return (
        !!window.ActiveXObject ||
        'ActiveXObject' in window ||
        navigator.userAgent.indexOf("'Trident") > -1
      )
    },
    // 获取谷歌浏览器版本
    isLowChromeEdition: function() {
      var version = this.getChromeVersion()
      if (version !== false && version <= 50) {
        return true
      }
      return false
    },
    getChromeVersion: function() {
      var arr = navigator.userAgent.split(' ')
      var chromeVersion = ''
      for (var i = 0; i < arr.length; i++) {
        if (/chrome/i.test(arr[i])) chromeVersion = arr[i]
      }
      try {
        if (chromeVersion) {
          var parts = chromeVersion.split('/')
          if (parts.length < 2) {
            return false
          }
          var versions = parts[1].split('.')
          if (versions.length < 2) {
            return false
          }
          return Number(versions[0])
        } else {
          return false
        }
      } catch (error) {
        return false
      }
    },
    isFlashPlay: function() {
      return this.isNewIE() || this.isLowChromeEdition() //微信pc客户端采用的是ie内核，故包含其中
    }
  }
  var isFlashPlay = condition.isFlashPlay()
  function speedPlay(_prismPlayer, player) {
    setTimeout(function() {
      var h = ''
      h +=
        '<div class="prism-setting-item prism-setting-speed" style="float: right; margin-top: 12px; margin-right: 15px; font-size: 16px; color: #fff;">倍速</div>'
      $('.prism-controlbar').append(h)
      var speed_h = ''
      speed_h += '<div class="prism-speed-selector prism-setting-selector">'
      speed_h += '<div class = "header">'
      speed_h += '<span style="margin-left: 20px;">倍速</span>'
      speed_h += '</div>'
      speed_h += '<ul class="selector-list">'
      speed_h += '<li><span>0.8X</span></li>'
      speed_h += '<li><span>正常</span></li>'
      speed_h += '<li><span>1.25X</span></li>'
      speed_h += '<li><span>1.5X</span></li>'
      speed_h += '<li><span>2X</span></li>'
      speed_h += '</ul>'
      speed_h += '</div>'
      $(_prismPlayer).append(speed_h)
      $('.prism-speed-selector span').each(function(index, item) {
        $(item).html() == condition.speedTxt &&
          $(item)
            .parent()
            .addClass('current')
      })
      $('.prism-setting-speed').click(function() {
        $('.line-selector-list').hide()
        $('.prism-speed-selector').toggle()
        $('.caption-panel') && $('.caption-panel').hide()
      })
      var speed = condition.speedList[condition.speedTxt]
      player.setSpeed(speed)
      $('.selector-list').click(function(e) {
        $('.selector-list li').removeClass('current')
        if ($(e.target).children().length > 0) {
          $(e.target).addClass('current')
          condition.speedTxt = $(e.target)
            .find('span')
            .html()
        } else {
          $(e.target)
            .parent()
            .addClass('current')
          condition.speedTxt = $(e.target).html()
        }
        speed = condition.speedList[condition.speedTxt]
        player.setSpeed(speed)
        $('.prism-speed-selector').hide()
      })
      $('#J_prismPlayer').hover(
        function() {},
        function() {
          $('.prism-speed-selector').hide() //hover移除时执行
          $('.line-selector-list').hide()
        }
      )
      $('.prism-speed-selector').hover(
        function() {
          //hover状态时执行
        },
        function() {
          $('.prism-speed-selector').hide() //hover移除时执行
          $('.line-selector-list').hide()
        }
      )
    }, 100)
  }
  // 添加线路切换按钮
  function addLineSelect(_prismPlayer) {
    // 当用户没有购买时，不显示切换按钮。Vue.prototype为当前vue对象
    if (Vue.prototype.course && Vue.prototype.course.is_purchased == 0 && Vue.prototype.course.is_free != 1) return
    setTimeout(function() {
      var selectLine = ''
      selectLine +=
        '<div class="prism-setting-item prism-setting-select-line" style="float: right; margin-top: 12px; margin-right: 15px; font-size: 16px; color: #fff;">切换线路</div>'
      // 如果是ie的flash播放
      $('.prism-controlbar').append(selectLine)
      var selectLineList = ''
      selectLineList +=
        '<ul class="line-selector-list">' +
        '<li class="line-selector-list-item' +
        (aliTimer.currentLine == 1 ? ' line-selector-list-item-active' : '') +
        '"><i class="iconfont icon-xianlu xianlu-item-icon">线路1</i></li>' +
        '<li class="line-selector-list-item' +
        (aliTimer.currentLine == 2 ? ' line-selector-list-item-active' : '') +
        '"><i class="iconfont icon-xianlu xianlu-item-icon">线路2</i></li>' +
        '</ul>'
      $(_prismPlayer).append(selectLineList)
      // 控制切换显示
      $('.prism-setting-select-line').click(function(e) {
        $('.line-selector-list').toggle()
        $('.prism-speed-selector').hide()
        $('.caption-panel') && $('.caption-panel').hide()
      })
      $('.line-selector-list').click(function(e) {
        e.stopPropagation()
        // 获取新的线路
        var currentParam = aliTimer.currentParam || {}
        if (!currentParam.courseId || !currentParam.video_id) return
        // 当前点击的元素
        var selectItemText = $(e.target).html()
        // 隐藏面板
        $('.line-selector-list').hide()
        // 线路一执行，
        if (selectItemText.indexOf('线路1') != -1) {
          // 当前路线下，点击当前路线不执行任何操作
          if (aliTimer.currentLine == 1) return
          // 将线路改为1
          aliTimer.currentLine = 1
          // 将当前状态改为正在切换线路
          aliTimer.isSelectLine = 1
          aliPlayerSelectEntry(currentParam)
        } else if (selectItemText.indexOf('线路2') != -1) {
          // 当前路线下，点击当前路线不执行任何操作
          if (aliTimer.currentLine == 2) return
          // 将线路改为2
          aliTimer.currentLine = 2
          // 获取新的播放地址
          getHlsVideoUrl(
            currentParam.courseId,
            currentParam.video_id,
            selectLineModel
          )
        }
      })
      $('#J_prismPlayer').hover(
        function() {},
        function() {
          $('.prism-speed-selector') && $('.prism-speed-selector').hide() //hover移除时执行
          $('.line-selector-list') && $('.line-selector-list').hide()
          $('.caption-panel') && $('.caption-panel').hide()
        }
      )
      $('.prism-speed-selector').hover(
        function() {
          //hover状态时执行
        },
        function() {
          $('.prism-speed-selector') && $('.prism-speed-selector').hide() //hover移除时执行
          $('.line-selector-list') && $('.line-selector-list').hide()
        }
      )

      // 新增字幕按钮（支持VTTCue浏览器，Edge，非IE浏览器）
      if (window.VTTCue) {
        addCaptionBtn(_prismPlayer)
      }
    }, 100)
  }
  // 字幕打开状态，一系列的设置
  function activateCaptionBtn() {
    // switch开关为打开状态
    $('#radioInput')[0].checked = true
    // 字幕按钮为激活状态
    $('.switch-dot').addClass('switch-dot-active')
    $('.caption-switch-img').attr(
      'src',
      '//image.zlketang.com/public/news/images/caption_on.png'
    )
  }
  // 关闭字幕，一系列的设置
  function deactiveCaptionBtn() {
    // switch开关为打开状态
    $('#radioInput')[0].checked = false
    // 字幕按钮为激活状态
    $('.switch-dot').removeClass('switch-dot-active')
    $('.caption-switch-img').attr(
      'src',
      '//image.zlketang.com/public/news/images/caption_off.png'
    )
  }
  // 初始化字幕 VTTCue
  async function initCaption(elVideo, success, fail) {
    if (!window.VTTCue) {
      Vue.prototype.$message.warning('IE浏览器不支持字幕，请使用其他浏览器')
      return
    }
    var textTrack = $('video')[0].textTracks[0]
    // 初始化一次后，不再初始化
    if (textTrack) {
      typeof success === 'function' && success()
      return
    }
    // 处理 textTrackCue 的起止时间
    function _getMil(time) {
      let result = 0
      time = time.trim()
      time = time.match(/[0-9:.]+/g)[0]
      let time1 = time.split('.')[0].split(':')
      time1 = time1.map(item => Number(item))
      result = time1[0] * 3600 + time1[1] * 60 + time1[2]
      result += Number('0.' + time.split('.')[1])
      return result
    }

    var vid = Vue.prototype.currentPlayParams ? Vue.prototype.currentPlayParams.video_id : ''
    if (!vid) {
      Vue.prototype.$message.warning('缺少视频id')
      return
    }
    var url = location.href
    var captionUrl = this.isClientProd
      ? `//image.zlketang.com\/project\/subtitle\/${vid % 1000}\/${vid}.vtt`
      : `//testcdn.zlketang.com\/project\/subtitle\/${vid % 1000}\/${vid}.vtt`
    // __test
    // captionUrl = 'https://testcdn.zlketang.com/project/subtitle/882/1882.vtt'
    // 获取字幕
    await fetch(captionUrl, {
      method: 'GET'
    })
      .then(res => {
        if (+res.status === 404) {
          return Promise.reject(404)
        }
        return res.text()
      })
      .then(res => {
        let track = elVideo.addTextTrack(
          'captions',
          '简体中文Subtitles',
          'zh_CN'
        )
        track.mode = 'showing'
        const arr = res.split('\n')
        for (let i = 0; i < arr.length; i++) {
          const line = arr[i]
          if (line.indexOf('-->') > -1) {
            const cue = line.split('-->')
            const startTime = cue[0].trim()
            const endTime = cue[1].trim()
            const text = arr[i + 1]
            const textTrackCue = new VTTCue(
              _getMil(startTime),
              _getMil(endTime),
              text
            )
            textTrackCue.id = i + 1
            track.addCue(textTrackCue)
          }
        }
        typeof success === 'function' && success()
      })
      .catch(e => {
        Vue.prototype.$message.error('字幕资源加载失败')
        $('#radioInput')[0].checked = false
        $('.switch-dot').removeClass('switch-dot-active')
        typeof fail === 'function' && fail()
      })
  }
  // 新增字幕按钮
  function addCaptionBtn(player, callback) {
    var captionBtn = ''
    captionBtn +=
      '<div class="prism-setting-item prism-setting-caption" style="height: 44px;line-height: 44px;float: right; margin-right: 15px; font-size: 16px; color: #fff;' +
      (!Vue.prototype.currentPlayParams || !Vue.prototype.currentPlayParams.subtitle ? 'display:none' : '') +
      '"><img class="caption-switch-img" src="//image.zlketang.com/public/news/images/caption_off.png" style="width:36px;height: 18px;vertical-align: middle;"/></div>'
    // 如果是ie的flash播放
    $('.prism-controlbar').append(captionBtn)
    $('.prism-setting-caption').click(function() {
      $('.prism-speed-selector').hide()
      $('.line-selector-list').hide()
      $('.caption-panel').toggle()
    })
    // 字幕操作面板
    var h = `<div
    class="caption-panel"
    style="
      position: absolute;
      display: none;
      right: 120px;
      z-index: 10000;
      bottom: 45px;
      width: 118px;
      background: rgba(60, 60, 60, .95);
      font-size: 14px;
      color: #ebecec;
      border-radius: 4px;
      padding: 12px;
      font-size: 12px;
    "
  >
    <div class="ovh">
      <span class="fl">字幕开关</span>
      <div class="switch-box fr">
          <div class="bg_con">
              <input id="radioInput" type="checkbox" class="switch"  value="0" />
              <label for="radioInput"></label>
          </div>
      </div> 
    </div>
    <div style="text-align:left;margin-top: 16px;">字幕大小</div>
    <div class="ovh tl mt10">
      <div class="operate-btn-small fl w33 tl">小</div>
      <div class="operate-btn-middle fl w33 tc">中</div>
      <div class="operate-btn-big fl w33 tr">大</div>
    </div>
    <div class="switch-bar">
      <div class="switch-bar-line" style="cursor:pointer"></div>
      <div class="switch-dot-left" style="cursor:pointer"></div>
      <div class="switch-dot-middle" style="cursor:pointer"></div>
      <div class="switch-dot-right" style="cursor:pointer"></div>
      <div class="switch-dot dot-middle"></div>
    </div>
  </div>`

    $(player).append(h)
    $('.switch-bar-line').click(function(e) {
      e.stopPropagation()
      var left = e.pageX - $('.box')[0].offsetLeft
      if (left >= 644 && left <= 670) {
        changeSmall()
      } else if (left > 670 && left <= 724) {
        changeMiddle()
      } else if (left > 724 && left <= 753) {
        changeBig()
      }
    })
    $('.switch-dot-left').click(function(e) {
      e.stopPropagation()
      changeSmall()
    })
    $('.switch-dot-middle').click(function(e) {
      e.stopPropagation()
      changeMiddle()
    })
    $('.switch-dot-right').click(function(e) {
      e.stopPropagation()
      changeBig()
    })
    $('.caption-panel').click(function(e) {
      // 阻止点击panel时向上冒泡，触发父元素事件
      e.stopPropagation()
    })
    $('#radioInput').change(function(e) {
      e.stopPropagation()
      var video = $('video')[0]
      var textTrack = video.textTracks[0]
      initCaption(video)
      if (this.checked) {
        $('.switch-dot').addClass('switch-dot-active')
        $('.caption-switch-img').attr(
          'src',
          '//image.zlketang.com/public/news/images/caption_on.png'
        )
        textTrack && (textTrack.mode = 'showing')
      } else {
        $('.switch-dot').removeClass('switch-dot-active')
        $('.caption-switch-img').attr(
          'src',
          '//image.zlketang.com/public/news/images/caption_off.png'
        )
        textTrack && (textTrack.mode = 'disabled')
      }
      video.play()
    })
    // 小字幕
    function changeSmall() {
      var isChecked = $('#radioInput')[0].checked
      if (!isChecked) {
        Vue.prototype.$message({
          type: 'warning',
          message: '请先打开字幕'
        })
        return
      }
      $('.switch-dot')
        .removeClass('dot-left')
        .removeClass('dot-middle')
        .removeClass('dot-right')
      $('.switch-dot-active').addClass('dot-left')
      $('.video-cue').remove()
      $(
        '<style class="video-cue">video::cue{font-size:16px;}</style>'
      ).appendTo('head')
    }
    // 中字幕
    function changeMiddle() {
      var isChecked = $('#radioInput')[0].checked
      if (!isChecked) {
        Vue.prototype.$message({
          type: 'warning',
          message: '请先打开字幕'
        })
        return
      }
      $('.switch-dot-active')
        .removeClass('dot-left')
        .removeClass('dot-middle')
        .removeClass('dot-right')
      $('.switch-dot-active').addClass('dot-middle')
      $('.video-cue').remove()
      $(
        '<style class="video-cue">video::cue{font-size:24px;}</style>'
      ).appendTo('head')
    }
    // 大字幕
    function changeBig() {
      var isChecked = $('#radioInput')[0].checked
      if (!isChecked) {
        Vue.prototype.$message({
          type: 'warning',
          message: '请先打开字幕'
        })
        return
      }
      $('.switch-dot-active')
        .removeClass('dot-left')
        .removeClass('dot-middle')
        .removeClass('dot-right')
      $('.switch-dot-active').addClass('dot-right')
      $('.video-cue').remove()
      $(
        '<style class="video-cue">video::cue{font-size:32px;}</style>'
      ).appendTo('head')
    }
    $('.operate-btn-small').click(function(e) {
      e.stopPropagation()
      changeSmall()
    })
    $('.operate-btn-middle').click(function(e) {
      e.stopPropagation()
      changeMiddle()
    })
    $('.operate-btn-big').click(function(e) {
      e.stopPropagation()
      changeBig()
    })
    typeof callback === 'function' && callback()
  }
  // 用户选择不同的播放线路
  function aliPlayerSelectEntry(params) {
    // 将传入得参数存起来以便切换线路使用,当商品id变换时才保存
    if (aliTimer.currentVideoId != params.video_id) {
      aliTimer.currentParam = {
        transUrl: params.transUrl,
        transHls: params.transHls,
        transVid: params.transVid,
        nextPlay: params.nextPlay,
        autoplayControl: params.autoplayControl,
        video_id: params.video_id,
        sts: params.sts,
        courseId: params.courseId,
        course_section_id: params.course_section_id
      }
    }
    // 如果当前播放线路为1默认播放线路
    if (aliTimer.currentLine == 1) {
      aliPlayerOpen(params)
    } else if (aliTimer.currentLine == 2) {
      var currentParams = {}
      try {
        currentParams = JSON.parse(JSON.stringify(params))
      } catch (error) {
        currentParams = params
      }
      getHlsVideoUrl(currentParams.courseId, currentParams.video_id, function(
        hls
      ) {
        currentParams.transUrl = 0
        currentParams.transHls = hls
        currentParams.transVid = 0
        aliPlayerOpen(currentParams)
      })
    }
    // 线路2播放时
  }
  function aliPlayerOpen(params) {
    // var transUrl = params.url,
    //   transHls = params.hls,
    //   transVid = params.alivid,
    var transUrl = params.url || params.transUrl,
      transHls = params.hls || params.transHls,
      transVid = params.alivid || params.transVid,
      nextPlay = params.nextPlay,
      autoplayControl = params.autoplayControl,
      video_id = params.video_id,
      sts = params.sts,
      courseId = params.courseId
    var coverPic = document.getElementsByClassName('cover-pic')[0]
    var nowTime = aliTimer.getTimestamp()
    // isSelectLine == 1时为点击切换线路，用户在10秒内点击播放相同视频按钮不执行
    if (
      aliTimer.currentVideoId &&
      aliTimer.currentVideoId == video_id &&
      Math.abs(aliTimer.currentvplayTime - nowTime) < 10 &&
      aliTimer.isSelectLine == 0
    ) {
      return
    }
    var J_prismPlayer = document.getElementById('J_prismPlayer')
    if (aliTimer.player) {
      try {
        // 播放器开启之后将状态置为0
        aliTimer.isSelectLine = 0
        aliTimer.player.dispose()
        $(J_prismPlayer).empty()
        aliTimer.player = false
      } catch (error) {}
    }
    aliTimer.currentVideoId = video_id
    aliTimer.currentvplayTime = nowTime
    transUrl = transUrl ? transUrl : '0'
    transHls = transHls ? transHls : '0'
    transVid = transVid ? transVid : '0'
    var useFlashPlayer = false
    if (isFlashPlay) {
      canFlash()
      useFlashPlayer = true
    } else {
      coverPic.innerHTML = "<p style='padding-top: 250px;'>视频加载中...</p>"
      coverPic.setAttribute('style', 'visibility: visible; opacity: 1;')
      useFlashPlayer = false
    }
    J_prismPlayer.innerHTML = '' //id为html里指定的播放器的容器id
    // J_prismPlayer.style = "height: 438px; z-index: 0;"
    var flashSkinLayout = [
        {
          name: 'H5Loading',
          align: 'cc'
        },
        { name: 'errorDisplay', align: 'tlabs', x: 0, y: 0 },
        { name: 'infoDisplay' },
        {
          name: 'controlBar',
          align: 'blabs',
          x: 0,
          y: 0,
          children: [
            { name: 'progress', align: 'tlabs', x: 0, y: 0 },
            { name: 'playButton', align: 'tl', x: 15, y: 25 },
            { name: 'timeDisplay', align: 'tl', x: 20, y: 25 },
            { name: 'fullScreenButton', align: 'tr', x: 20, y: 25 },
            { name: 'speedButton', align: 'tr', x: 10, y: 25 },
            // { name: "streamButton", align: "tr", x: 10, y: 12 },
            { name: 'volume', align: 'tl', x: 20, y: 25 }
          ]
        }
      ],
      H5SkinLayout = [
        {
          name: 'H5Loading',
          align: 'cc'
        },
        { name: 'bigPlayButton', align: 'blabs', x: 30, y: 80 },
        { name: 'errorDisplay', align: 'tlabs', x: 0, y: 0 },
        { name: 'infoDisplay' },
        {
          name: 'controlBar',
          align: 'blabs',
          x: 0,
          y: 0,
          children: [
            { name: 'progress', align: 'tlabs', x: 0, y: 0 },
            { name: 'playButton', align: 'tl', x: 15, y: 12 },
            { name: 'timeDisplay', align: 'tl', x: 20, y: 6 },
            { name: 'fullScreenButton', align: 'tr', x: 20, y: 12 },
            { name: 'speedButton', align: 'tr', x: 10, y: 12 },
            // { name: "setting", align: "tr", x: 15, y: 12 },
            { name: 'errorDisplay', align: 'tlabs', x: 0, y: 5 },
            { name: 'volume', align: 'tl', x: 20, y: 12 }
          ]
        }
      ]
    // 初始化阿里播放器
    var playParams = {
      id: 'J_prismPlayer',
      autoplay: true,
      skinLayout: isFlashPlay ? flashSkinLayout : H5SkinLayout,
      useFlashPrism: useFlashPlayer,
      diagnosisButtonVisible: false
      // useFlashPrism: true
    }
    // 在play.html页面当切换播放线路时执行此方法
    if (location.href.indexOf('play.html') && Vue.prototype.checkPlayRoute) {
      // 在play页面也执行了checkPlayRoute中的readyPlayer回调
      // 此处主要是给回调上锁，避免重复执行
      Vue.prototype.doReadyPlayer=true
      Vue.prototype.checkPlayRoute()
      Vue.prototype.doReadyPlayer=false
    } 
    if (transVid != '0' && transHls == '0') {
      aliTimer.checkRefreshSts(function(sts) {
        playParams.vid = transVid
        playParams.accessKeyId = sts.accessKeyId
        playParams.securityToken = sts.securityToken
        playParams.accessKeySecret = sts.accessKeySecret
        playParams.format = 'm3u8'
        try {
          aliTimer.player = new Aliplayer(playParams)
        } catch (error) {
          $('#J_prismPlayer').remove()
          $('#playerbox').append(
            '<div class="prism-player" id="J_prismPlayer" ref="J_prismPlayer" style="height: 505px; width: auto;" >'
          )
          aliTimer.player = new Aliplayer(playParams)
          J_prismPlayer = document.getElementById('J_prismPlayer')
        }
        setPlayerHandler(
          aliTimer.player,
          nextPlay,
          J_prismPlayer,
          autoplayControl,
          video_id,
          courseId
        )
        !useFlashPlayer ? speedPlay(J_prismPlayer, aliTimer.player) : '' //h5倍速播放。
        !useFlashPlayer ? addLineSelect(J_prismPlayer) : ''
      })
    } else {
      playParams.source = transUrl == '0' ? transHls : transUrl
      if (window.tool && window.tool.fixVideoSrc) {
        playParams.source = window.tool.fixVideoSrc(playParams.source)
      }
      playParams.format = transUrl == '0' ? 'm3u8' : 'mp4'
      aliTimer.player = new Aliplayer(playParams)
      setPlayerHandler(
        aliTimer.player,
        nextPlay,
        J_prismPlayer,
        autoplayControl,
        video_id,
        courseId
      )
      !useFlashPlayer ? speedPlay(J_prismPlayer, aliTimer.player) : '' //h5倍速播放。
      !useFlashPlayer ? addLineSelect(J_prismPlayer) : ''
    }
  }
  // 获取视频的hls地址，线路2播放模式
  function getHlsVideoUrl(courseId, video_id, callback) {
    // hls链接
    var hls,
      timeStamp = aliTimer.getTimestamp()
    // 当用户重复点击时就用本地链接,链接保存半小时
    if (
      aliTimer['currentHls_' + video_id] &&
      timeStamp - aliTimer['currentHls_' + video_id].expire < 0.5 * 3600
    ) {
      hls = aliTimer['currentHls_' + video_id].hls
      callback && callback(hls)
      return
    }
    axios({
      url: '/wxpub/api/video',
      method: 'post',
      data: {
        course_id: courseId,
        video_id: video_id
      },
      // 添加签名
      headers: {
        'App-Video-Sign': hex_md5(timeStamp + courseId + video_id),
        'App-Video-Timestamp': timeStamp
      }
    })
      .then(function(res) {
        var result = res.data
        if (result.data && result.errcode === 0) {
          hls = window.atob(window.atob(result.data.token)) || ''
          // 将请求回来的链接保存，当用户重复点击时就用本地链接
          aliTimer['currentHls_' + video_id] = {
            hls: hls,
            expire: timeStamp
          }
          callback && callback(hls)
        } else {
          bus.$message({
            message: '线路切换失败',
            type: 'warning'
          })
        }
      })
      .catch(function(e) {
        bus.$message({
          message: '线路切换失败',
          type: 'warning'
        })
      })
  }
  // 用户点击切换线路执行
  function selectLineModel(hls) {
    // 重启新的线路开启播放器,1表示当前视频重新切换线路，开启播放器后将其重置为0
    aliTimer.isSelectLine = 1
    var currentParam = {}
    try {
      currentParam = JSON.parse(JSON.stringify(aliTimer.currentParam))
    } catch (error) {
      currentParam = aliTimer.currentParam
    }
    if (!currentParam.courseId || !currentParam.video_id) return
    currentParam.transUrl = 0
    currentParam.transHls = hls
    currentParam.transVid = 0
    aliPlayerOpen(currentParam)
  }
  var aliTimer = {
    //只有课程才有
    timerId: false,
    sts: false,
    player: false,
    timeupdateTimerId: false,
    lastStsTimestamp: false,
    refreshFailCount: 0,
    autoPlayCount: 0,
    currentVideoId: false, //当前视频播放id
    currentvplayTime: 0, //当前视频播放时间
    currentParam: {}, //将用户点击默认线路时的视频信息参数保存下来（vid播放模式），用于切换线路时使用
    isSelectLine: 0, //是否是重选线路，1表示是
    currentLine: 1, //当前线路（默认是1）
    init: function(sts) {
      typeof sts == 'object' && aliTimer.start()
      aliTimer.setSts(sts)
      aliTimer.refreshFailCount = 0
      aliTimer.currentVideoId = false
      aliTimer.currentvplayTime = 0
    },
    start: function() {
      if (aliTimer.timerId) {
        return
      }
      aliTimer.timerId = setInterval(function() {
        //定时存储播放进去
        aliTimer.checkRefreshSts() //启动sts检查
      }, 10 * 1000)
    },
    getTimestamp: function() {
      var timestamp = Date.parse(new Date())
      return parseInt(timestamp / 1000)
    },
    setSts: function(sts) {
      if (sts && typeof sts == 'object') {
        aliTimer.sts = sts
        //zl.timer.sts.expire = 70;
        aliTimer.lastStsTimestamp = aliTimer.getTimestamp()
      }
    },
    checkRefreshSts: function(callback) {
      if (!aliTimer.sts) {
        //当sts没有初始值，无需更新
        //当的确发送callback，通常play，强制启动获取刷新sts防止误判
        callback && aliTimer.refreshStsModel(callback)
        return
      }
      var diffTime = aliTimer.getTimestamp() - aliTimer.lastStsTimestamp
      //预留60s,已经过期
      if (diffTime > aliTimer.sts.expire - 300) {
        aliTimer.refreshStsModel(callback)
        return
      }
      callback && callback(aliTimer.sts)
    },
    checkTimer: function(callback) {
      if (aliTimer.refreshFailCount > 6) {
        //防止过的失败次数
        if (aliTimer.timerId) {
          clearInterval(aliTimer.timerId)
          aliTimer.timerId = false
        }
      }
    },
    refreshStsModel: function(callback) {
      aliTimer.refreshFailCount++
      aliTimer.checkTimer()
      axios
        .get('/wxpub/api/sts', {
          params: {
            timestamp: aliTimer.getTimestamp()
          }
        })
        .then(function(result) {
          if (result && result.data.errcode == '1001') {
            bus
              .$alert('当前会话已过期，请重新登录后再观看', '温馨提示:', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              })
              .then(function() {
                location.href = '/login.html'
              })
            if (aliTimer.timerId) {
              clearInterval(aliTimer.timerId)
              aliTimer.timerId = false
            }
            return
          }
          if (result && result.data.data) {
            aliTimer.refreshFailCount = 0
            aliTimer.setSts(result.data.data)
            callback && callback(aliTimer.sts)
          } else {
            aliTimer.checkTimer(callback)
          }
        })
    }
  }

  var playTimeMap = null //播放时长临时变量
  var preProgress = null //上一次记录的进度值（秒数）
  var pushInterval = 120 //上传进度时间间隔（秒）
  var pushTimer = 0 //上传进度计时
  var pushFlag = false //是否在上传进度
  var currentSeeTime = 0 //当前视频，观看的时长

  var setPlayerHandler = function(
    player,
    nextPlay,
    J_prismPlayer,
    autoplayControl,
    video_id,
    courseId
  ) {
    // 设置错误状态session
    //         一.主动提示用户刷新或者切换线路， 状态码为1

    // 二当用户已经进行过线路切换后，还是无法播放	2
    // 		1.提示用户关闭路由器，10分钟后重启，更新本地cdn节点()
    // 		2.还是不行请用户检查当前网络状态，
    // 			a.如果是公司网络（请咨询公司网络是否限制本站资源观看，可以同时打开优酷或者腾讯视频检验）

    // 三最后还是不行请联系技术支持（） 3
    var coverPic = document.getElementsByClassName('cover-pic')[0]
    var course_id = 'course_' + video_id
    if (playTimeMap != null) {
      localStorage.setItem(
        'playTimeInc' + courseId,
        JSON.stringify(playTimeMap)
      )
      playTimeMap = null
    }
    preProgress = null
    pushFlag = false

    if (aliTimer.timeupdateTimerId) {
      clearInterval(aliTimer.timeupdateTimerId)
      aliTimer.timeupdateTimerId = null
    }
    //第一次播放取消自动播放
    player.on('ready', function(e) {
      try {
        var errorStatusCode = {}
        errorStatusCode['errorStatusCode_' + courseId + '_' + video_id] = 0
        sessionStorage.setItem(
          'errorStatusCode',
          JSON.stringify(errorStatusCode)
        )
      } catch (error) {}

      coverPic.setAttribute('style', 'visibility: hidden; opacity: 0;')
      !isFlashPlay ? clickPlay(J_prismPlayer) : ''
      try {
        aliTimer.player.setVolume(0.5)
      } catch (err) {}

      if (aliTimer.timeupdateTimerId) {
        clearInterval(aliTimer.timeupdateTimerId)
        aliTimer.timeupdateTimerId = null
      }

      aliTimer.timeupdateTimerId = setInterval(function() {
        if (!aliTimer.player) {
          return
        }

        var currentTime = aliTimer.player.getCurrentTime()
        var status = aliTimer.player.getStatus()
        if (!currentTime) return false
        if (
          status == 'playing' ||
          status == 'play' ||
          status == 'ready' ||
          status == 'waiting'
        ) {
          try {
            var duration = parseInt(aliTimer.player.getDuration())
            var currentTime = parseInt(aliTimer.player.getCurrentTime())
            var step = 30
            if (duration - currentTime <= step) {
              currentTime = duration - step
            }
            localStorage.setItem(course_id, currentTime)
          } catch (e) {}
        }

        //记录播放时长
        if (preProgress == null || currentTime <= preProgress) {
          //不计入播放时长
          preProgress = currentTime
        } else {
          var inc = 2
          if (currentTime - preProgress < 2) {
            inc = currentTime - preProgress
          }
          preProgress = currentTime

          if (playTimeMap == null) {
            //初始化播放时长变量
            var playTimeInc = localStorage.getItem('playTimeInc' + courseId)
            if (!playTimeInc) {
              playTimeMap = {}
            } else {
              playTimeMap = JSON.parse(playTimeInc)
            }
          }

          if (!playTimeMap[aliTimer.currentVideoId]) {
            playTimeMap[aliTimer.currentVideoId] = 0
          }
          playTimeMap[aliTimer.currentVideoId] += inc
          if (!pushFlag) {
            //没有在上传进度则更新本地数据
            localStorage.setItem(
              'playTimeInc' + courseId,
              JSON.stringify(playTimeMap)
            )
          }

          pushTimer += inc
          //如果当前播放时间在75%-85%之间，并且有班级权限的用户立即上报进度
          try {
            var rate =
              parseInt(aliTimer.player.getCurrentTime()) /
              parseInt(aliTimer.player.getDuration())
            if (
              Vue.prototype &&
              !Vue.prototype.isUped &&
              Vue.prototype.isInClass &&
              rate > 0.75 &&
              rate < 0.85
            ) {
              Vue.prototype.isUped = true
              pushVideoProgress(courseId)
              pushFlag = true
              playTimeMap = {}
              pushTimer = 0
            }
          } catch (error) {}
          if (pushTimer >= pushInterval) {
            //间隔一段时间上传播放进度
            pushVideoProgress(courseId)
            pushFlag = true
            playTimeMap = {}
            pushTimer = 0
          }
        }
      }, 2 * 1000)
      if (!autoplayControl) {
        autoplayControl = true
        try {
          player.pause()
        } catch (e) {}
      }
    })
    //由暂停恢复播放触发
    player.on('play', function(e) {
      coverPic.setAttribute('style', 'visibility: hidden; opacity: 0;')
    })
    var seeked = false
    var eventName = isFlashPlay ? 'loadedmetadata' : 'canplaythrough'
    player.on(eventName, function(e) {
      if (!seeked) {
        var getTime = localStorage.getItem(course_id)
        if (getTime && getTime > 5) {
          try {
            player.seek(getTime - 5)
          } catch (e) {}
          seeked = true
        }
      }
    })

    //自动播放下一视频
    player.on('ended', function(e) {
      if (nextPlay == null) {
        coverPic.innerHTML =
          "<p style='padding-top: 250px;'>本课程已全部播放完毕。</p>"
        coverPic.setAttribute(
          'style',
          'visibility: visible; opacity: 1; transition: 0.3s'
        )
        return false
      }
      // 重置上一个视频的播放时长
      currentSeeTime = 0
      if (!isFlashPlay) {
        aliTimer.autoPlayCount++
        if (aliTimer.autoPlayCount < 4) {
          //最多自动播放三个
          coverPic.innerHTML =
            "<p style='padding-top: 250px;'>正在准备播放下一个视频...</p>"
          if (Vue.prototype.selectNode) {
            Vue.prototype.selectNode(nextPlay, false)
            return
          }
          setTimeout(function() {
            bus.$emit('NEXTPLAY', nextPlay)
          }, 500)
        } else {
          coverPic.innerHTML =
            "<p style='padding-top: 250px;'>自动播放已结束</p>"
        }
        coverPic.setAttribute(
          'style',
          'visibility: visible; opacity: 1; transition: 0.3s'
        )
      } else {
        coverPic.innerHTML =
          "<p style='padding-top: 250px;'>本章节已播放结束</p>"
        coverPic.setAttribute(
          'style',
          'visibility: visible; opacity: 1; transition: 0.3s'
        )
        setTimeout(function() {
          coverPic.setAttribute(
            'style',
            'visibility: hidden; opacity: 0; transition: 0.3s'
          )
        }, 1500)
      }
      // return
    })
    var retryCount = 0
    var currentvplayTime = aliTimer.currentvplayTime
    player.on('error', function(e) {
      var paramData = e.paramData
      coverPic.setAttribute('style', 'visibility: visible; opacity: 1;')
      if (paramData.errortype) {
        // flash 错误
        coverPic.innerHTML =
          "<p style='padding-top: 250px;'>网络错误，请确认您的网络是否稳定或者连接异常。</p>"
        return
      }
      //H5错误
      try {
        var err_operation = J_prismPlayer.getElementsByClassName(
          'prism-error-operation'
        )[0]
        var info = J_prismPlayer.getElementsByClassName('prism-detect-info')[0]
        var err_content = J_prismPlayer.getElementsByClassName(
          'prism-error-content'
        )[0]
        // err_content.setAttribute('style', 'margin-top: 200px;')
        err_content.setAttribute('style', 'display: none;')
        err_operation.setAttribute('style', 'display: none;')
        info.setAttribute('style', 'display: none;')
      } catch (e) {}

      /*不支持重新play的错误码*/
      // if (
      //   paramData.error_code != 4016 &&
      //   paramData.error_code != 4003 &&
      //   paramData.error_code != 4006
      // ) {
      //   coverPic.innerHTML =
      //   '<div style="text-align:center;height:100%;box-sizing: border-box;padding-top: 110px;">' +
      //   '  <img src="//image.zlketang.com/public/news/images/guanwangPic/fail.png" class="mb10" style="height:112px;width:150px">' +
      //   '  <p class="f16 white tc mb10">出了点小状况，视频播放依然失败...</p>' +
      //   '  <p class="f16 tc mb10" style="color:#AAAAAA;">网络连接异常: </p>' +
      //   '  <p class="f16 tc mb10" style="color:#AAAAAA;">&nbsp;&nbsp;1、若是家用网络，建议您关闭路由器10分钟后重启。</p>' +
      //   '  <p class="f16" style="color:#AAAAAA;">2、若是公司网络，请联系公司网络管理员处理。&nbsp;&nbsp;&nbsp;&nbsp;</p>' +
      //   '  <span class="inline-center cursor" style="padding: 0 20px;margin-top: 50px;color:#AAAAAA;height:32px;line-height: 32px;border:1px solid rgba(170,170,170,1);border-radius:6px;">如有疑问，请联系技术支持QQ：2051682785</span>' +
      //   '</div>'
      //   return
      // }
      setTimeout(function() {
        try {
          /*防止视频已经切换*/
          // if (currentvplayTime != aliTimer.currentvplayTime) {
          //   return
          // }
          retryCount++
          if (retryCount > 1) {
            coverPic.setAttribute('style', 'visibility: visible; opacity: 1;')
            //超过最大的重试次数,后提示不同的文案
            var errorStatusCode = sessionStorage.getItem('errorStatusCode')
              ? JSON.parse(sessionStorage.getItem('errorStatusCode'))
              : {}
            // 没有状态码的情况
            if (
              !errorStatusCode[
                'errorStatusCode_' + courseId + '_' + video_id
              ] ||
              +errorStatusCode[
                'errorStatusCode_' + courseId + '_' + video_id
              ] === 0
            ) {
              errorStatusCode[
                'errorStatusCode_' + courseId + '_' + video_id
              ] = 1
              sessionStorage.setItem(
                'errorStatusCode',
                JSON.stringify(errorStatusCode)
              )
              coverPic.innerHTML =
                '<div style="text-align:center;height:100%;box-sizing: border-box;padding-top: 110px;">' +
                '  <img src="//image.zlketang.com/public/news/images/guanwangPic/fail.png" class="mb10" style="height:112px;width:150px">' +
                '  <p class="f16 white tc mb10">出了点小状况，视频播放失败...</p>' +
                '  <p class="f16 white tc mb20">请您尝试刷新或者切换线路</p>' +
                '  <span  id="qiehuanbtn" class="inline-center cursor" style="width:96px;height:34px;background:linear-gradient(75deg,rgba(0,217,226,1) 0%,rgba(27,255,207,1) 100%);border-radius:17px;line-height: 34px;">切换线路</span>' +
                '</div>'
              $('#qiehuanbtn').click(function() {
                var currentParam = aliTimer.currentParam || {}
                // 获取新的线路
                if (aliTimer.currentLine == 2) {
                  // 将线路改为1
                  aliTimer.currentLine = 1
                  // 将当前状态改为正在切换线路
                  aliTimer.isSelectLine = 1
                  var J_prismPlayer = document.getElementById('J_prismPlayer')
                  $(J_prismPlayer).empty()
                  if (aliTimer && aliTimer.player) {
                    aliTimer.player.dispose()
                  }
                  aliPlayerSelectEntry(currentParam)
                } else if (aliTimer.currentLine == 1) {
                  // 将线路改为2
                  aliTimer.currentLine = 2
                  // 获取新的播放地址
                  getHlsVideoUrl(
                    currentParam.courseId,
                    currentParam.video_id,
                    selectLineModel
                  )
                }
              })
            } else if (
              errorStatusCode &&
              +errorStatusCode[
                'errorStatusCode_' + courseId + '_' + video_id
              ] === 1
            ) {
              errorStatusCode[
                'errorStatusCode_' + courseId + '_' + video_id
              ] = 2
              sessionStorage.setItem(
                'errorStatusCode',
                JSON.stringify(errorStatusCode)
              )
              coverPic.innerHTML =
                '<div style="text-align:center;height:100%;box-sizing: border-box;padding-top: 110px;">' +
                '  <img src="//image.zlketang.com/public/news/images/guanwangPic/fail.png" class="mb10" style="height:112px;width:150px">' +
                '  <p class="f16 white tc mb10">出了点小状况，视频播放依然失败...</p>' +
                '  <p class="f16 tc mb10" style="color:#AAAAAA;">网络连接异常: </p>' +
                '  <p class="f16 tc mb10" style="color:#AAAAAA;">&nbsp;&nbsp;1、若是家用网络，建议您关闭路由器10分钟后重启。</p>' +
                '  <p class="f16" style="color:#AAAAAA;">2、若是公司网络，请联系公司网络管理员处理。&nbsp;&nbsp;&nbsp;&nbsp;</p>' +
                '  <span class="inline-center cursor" style="padding: 0 20px;margin-top: 50px;color:#AAAAAA;height:32px;line-height: 32px;border:1px solid rgba(170,170,170,1);border-radius:6px;">如有疑问，请联系技术支持QQ：2051682785</span>' +
                '</div>'
            } else if (
              errorStatusCode &&
              +errorStatusCode[
                'errorStatusCode_' + courseId + '_' + video_id
              ] === 2
            ) {
              coverPic.innerHTML =
                '<div style="text-align:center;height:100%;box-sizing: border-box;padding-top: 110px;">' +
                '  <img src="//image.zlketang.com/public/news/images/guanwangPic/fail.png" class="mb10" style="height:112px;width:150px">' +
                '  <p class="f16 white tc mb10">出了点小状况，视频播放依然失败...</p>' +
                '  <p class="f16 tc mb10" style="color:#AAAAAA;">始终无法观看视频</p>' +
                '  <p class="f16" style="color:#AAAAAA;">请联系技术支持QQ：2051682785</p>' +
                '</div>'
            }
            return
          }
          if (player.getStatus() == 'playing') {
            //当前已经在播放，无需播放
            coverPic.setAttribute('style', 'visibility: hidden; opacity: 0;')
            return
          }
          try {
            var duration = parseInt(player.getDuration())
            var currentTime = parseInt(player.getCurrentTime())
            var remainTime = 10
            if (duration - currentTime <= remainTime) {
              return
            }
          } catch (e) {}
          //重试播放
          player.play()
          coverPic.setAttribute('style', 'visibility: hidden; opacity: 0;')
        } catch (e) {}
      }, 500)
    })
  }
  // 通过async 延时获取controlBox[0]
  function clickPlay(J_prismPlayer) {
    var controlBox = J_prismPlayer.getElementsByClassName('prism-controlbar')
    var settingList = J_prismPlayer.getElementsByClassName('prism-setting-list')
    var settingSelects = J_prismPlayer.getElementsByClassName(
      'prism-setting-selector'
    )
    var playVol = J_prismPlayer.getElementsByClassName('prism-volume-control')
    if (controlBox && controlBox[0]) {
      controlBox[0].addEventListener('click', function(event) {
        event.stopPropagation()
      })
    }
    if (playVol && playVol[0]) {
      playVol[0].addEventListener('click', function(event) {
        event.stopPropagation()
      })
    }
    if (settingList && settingList[0]) {
      settingList[0].addEventListener('click', function(event) {
        event.stopPropagation()
      })
    }
    if (playVol && playVol[0]) {
      playVol[0].addEventListener('click', function(event) {
        event.stopPropagation()
      })
    }
    if (settingSelects && settingSelects.length > 0) {
      for (var i = 0; i < settingSelects.length; i++) {
        settingSelects[i].addEventListener('click', function(event) {
          event.stopPropagation()
        })
      }
    }
    document.onkeydown = function(e) {
      //阻止空格键滚动页面。
      //空格控制播放暂停。
      // 上下左右键
      var keyNum = window.event ? e.keyCode : e.which
      if (e.preventDefault) {
        keyNum == 32 && e.preventDefault()
        keyNum == 37 && e.preventDefault()
        keyNum == 38 && e.preventDefault()
        keyNum == 39 && e.preventDefault()
        keyNum == 40 && e.preventDefault()
      } else {
        if (
          keyNum == 32 ||
          keyNum == 37 ||
          keyNum == 38 ||
          keyNum == 39 ||
          keyNum == 40
        ) {
          window.event.returnValue = false
        }
      }
      if (keyNum == 32 && aliTimer.player.getStatus() !== 'playing') {
        aliTimer.player.play()
      }
      if (keyNum == 32 && aliTimer.player.getStatus() == 'playing') {
        aliTimer.player.pause()
      }
      if (keyNum == 32) return
      // 下面是键盘快进和快退音量加减
      try {
        $('.prism-controlbar').fadeIn()
        // 获取视频总时长
        var videotimes = aliTimer.player.getDuration()
        // 获取当前的时长
        var playnum = aliTimer.player.getCurrentTime()
        // 视频快退，设置为10秒
        if (keyNum == 37) {
          // 视频快退，设置为5秒
          playnum = parseInt(playnum - 5)
          if (playnum > 6) {
            aliTimer.player.seek(playnum)
          }
        }
        // 视频快进10秒
        if (keyNum == 39) {
          playnum = parseInt(playnum + 5)
          if (playnum < videotimes - 5) {
            aliTimer.player.seek(playnum)
          }
        }
        // 键盘音量加
        if (keyNum != '38' && keyNum != '40') return
        $('.prism-volume-control').fadeIn()
        if (keyNum == 38) {
          var volume = Math.ceil(aliTimer.player.getVolume() * 100)
          if (volume < 100) {
            volume = (volume + 1) / 100
            aliTimer.player.setVolume(volume)
          }
        }
        // 键盘音量减
        if (keyNum == 40) {
          var volume = Math.floor(aliTimer.player.getVolume() * 100)
          if (volume > 0) {
            volume = (volume - 1) / 100
            aliTimer.player.setVolume(volume)
          }
        }
      } catch (error) {}
    }
    // 按键抬起，隐藏控制面板
    document.onkeyup = function(e) {
      //阻止空格键滚动页面。
      //空格控制播放暂停。
      // 上下左右键
      var keyNum = window.event ? e.keyCode : e.which
      if (e.preventDefault) {
        keyNum == 32 && e.preventDefault()
        keyNum == 37 && e.preventDefault()
        keyNum == 38 && e.preventDefault()
        keyNum == 39 && e.preventDefault()
        keyNum == 40 && e.preventDefault()
      } else {
        if (
          keyNum == 32 ||
          keyNum == 37 ||
          keyNum == 38 ||
          keyNum == 39 ||
          keyNum == 40
        ) {
          window.event.returnValue = false
        }
      }
      // 空格键忽略
      if (keyNum == '32') return
      if (controlTimer) {
        clearTimeout(controlTimer)
        controlTimer = null
      }
      controlTimer = setTimeout(function() {
        $('.prism-volume-control').hide()
        $('.prism-controlbar').hide()
      }, 1000)
    }
    J_prismPlayer.addEventListener('click', function() {
      if (aliTimer.player.getStatus() !== 'playing') {
        aliTimer.player.play()
      }
      if (aliTimer.player.getStatus() == 'playing') {
        aliTimer.player.pause()
      }
    })
  }
  //判断是否启用flash
  function canFlash() {
    var coverPic = document.getElementsByClassName('cover-pic')[0]
    var flag = false
    if (window.ActiveXObject) {
      try {
        var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash')
        if (swf) {
          flag = true
        }
      } catch (e) {}
    } else {
      try {
        var swf = navigator.plugins['Shockwave Flash']
        if (swf) {
          flag = true
        }
      } catch (e) {}
    }
    if (!flag) {
      // coverPic.setAttribute('style', 'visibility: hidden; opacity: 0; transition: 0.3s')
      coverPic.innerHTML =
        "<p style='padding-top: 250px;'>当前播放需启用flash插件 </p>"
      coverPic.innerHTML +=
        '<a style="text-decoration: underline; color: #409EFF;" href="https://flash.2144.com/?activex" target="_blank">去安装</a>'
    }
  }

  function pushVideoProgress(courseId) {
    if (!localStorage.getItem('user')) {
      return
    }
    var playTimeInc = localStorage.getItem('playTimeInc' + courseId)
    if (!playTimeInc) {
      return
    }
    var videos = []
    try {
      playTimeInc = JSON.parse(playTimeInc)
      for (var vid in playTimeInc) {
        var progress_second = localStorage.getItem('course_' + vid)
        if (!progress_second || !playTimeInc[vid]) {
          continue
        }
        var video = {
          course_id: courseId,
          video_id: vid,
          progress_second: progress_second,
          play_second: playTimeInc[vid]
        }
        videos.push(video)
      }
    } catch (error) {}

    if (videos.length == 0) {
      return
    }
    // 获取当前视频播放进度,Vue.prototype为vue对象
    try {
      var userSelect = Vue.prototype.userSelect,
        class_id = 0,
        teacher_id = 0
      if (userSelect) {
        class_id = Vue.prototype.classesId || 0
        teacher_id = userSelect.teacher_id || 0
      }
      currentSeeTime += playTimeInc[vid]
      var currentProcess = {
        t: currentSeeTime, //播放时长
        s: Math.round(progress_second) || 0 //播放进度
      }
      // 用户画像watch_video，上传
      var params = {
        class_id: +class_id,
        teacher_id: +teacher_id,
        video_id: +vid,
        progress: currentProcess,
        course_id: +courseId
      }
      if (window.zlSa) {
        zlSa.watchVideo(params)
      }
    } catch (error) {}
    axios({
      url: '/storage/video/push_progress',
      method: 'post',
      data: {
        from: 'wxpub',
        videos: videos,
        last_vid: aliTimer.currentVideoId
      },
      timeout: 2000
    })
      .then(function(res) {
        if (res.data.errcode == '0') {
          localStorage.removeItem('playTimeInc' + courseId)
        } else {
          playTimeMap = null
        }
        pushFlag = false
      })
      .catch(function(error) {
        playTimeMap = null
        pushFlag = false
      })
  }
  window.aliPlayerSelectEntry = aliPlayerSelectEntry
  window.aliTimer = aliTimer
})()
